/*
 *  Copyright (c) Skrumtious
 */
package com.skrumtious.action;

import com.skrumtious.action.bean.ErrorBean;
import com.skrumtious.backend.DoRemoveSkrumItemRequest;
import com.skrumtious.backend.DoRemoveSkrumItemResponse;
import com.skrumtious.backend.SkrumService;
import com.skrumtious.backend.SkrumServiceFactory;

/**
 * @author Tony
 *
 */
public class RemoveSkrumItemWebAction implements WebAction {

	/* (non-Javadoc)
	 * @see com.skrumtious.action.WebAction#doAction(com.skrumtious.action.WebRequest)
	 */
	@Override
	public WebResponse doAction(WebRequest request) throws Exception {
		WebResponse response = null;
						
		int tabId = request.getParamAsInt("tabId");
		int itemId = request.getParamAsInt("itemId");
		
		DoRemoveSkrumItemRequest skrumRequest = new DoRemoveSkrumItemRequest(request.getUserId(), tabId, itemId);
		
		SkrumService skrumService = SkrumServiceFactory.getSkrumService();
		DoRemoveSkrumItemResponse skrumResponse = skrumService.removeSkrumItem(skrumRequest);
				
		if ( ! skrumResponse.isSuccess() ) {
			String errorMsg = skrumResponse.getHumanReadableError();
			ErrorBean errorBean = new ErrorBean(errorMsg);
			request.setBean(ErrorBean.BEAN_NAME, errorBean);
			
			response = new WebResponse(true, false, "error.jsp");
		}
		else {							
			response = new WebResponse(false, false, "");
		}
						
		return response;
	}

}
